﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace DBtuning
{
    public partial class Param_3 : System.Web.UI.Page
    {
        private FetchData fetch = new FetchData();
        private static DateTime from,to;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["id"] != null)
                    this.LabelParam.Text = (string)Session["id"];

                if (this.Request["time"] != null)
                {
                    string time = this.Request["time"];
                    string[] t = Regex.Split(time, "---");
                    from = Convert.ToDateTime(t[0]);                
                    to = Convert.ToDateTime(t[1]);
                }
            }
        }

        protected void view_Click(object sender, EventArgs e)
        {
            int interval = Int16.Parse(DropDownList1.Text.Substring(0, DropDownList1.Text.Length - 3));
            if (interval >= (int)Session["interval"])
            {
                MessageBox.Show("The interval time shou be less than" + Session["interval"].ToString());
                return;
            }
            DataTable dt = new DataTable();
            dt = fetch.GetDetails(this.LabelParam.Text, interval, from, to);
            Session["Data"] = dt;
            GridView_Param.DataSource = dt;
            GridView_Param.DataBind();
        }

        protected void LBtnBack_Click(object sender, EventArgs e)
        {
            this.Response.Redirect("Param_2.aspx");
        }

        protected void GridView_Param_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            if (Session["Data"] == null)
                return;
            GridView_Param.DataSource = (DataTable)Session["Data"];
            GridView_Param.PageIndex = e.NewPageIndex;
            GridView_Param.DataBind();
        }
    }
}
